<?php
include_once( 'initlite.php' );
$since_id = (int)$_GET['since'] ? (int)$_GET['since'] : 0;
$max_id = (int)$_GET['max'] ? (int)$_GET['max'] : 0;
$page = (int)$_GET['page'] ? (int)$_GET['page'] : 1;
$count = (int)$_GET['count'] ? (int)$_GET['count'] : 10;
if($_GET["type"] == "sentcomments"){
	$ptl = $c->comments_by_me($page, $count, $since_id, $max_id);
}
else if($_GET["type"] == "mentioncomments"){
	$ptl = $c->comments_mentions($page, $count, $since_id, $max_id);
	$c->reset_count('mention_cmt');
}
else{
	$ptl = $c->comments_to_me($page, $count, $since_id, $max_id);
	$c->reset_count('cmt');
}
$timeline = $ptl["comments"];
for($i=0; $i<count($timeline); $i++){
	$thistimeline = $timeline[$i];
	$statePostUserHead = $thistimeline["user"]["profile_image_url"];
	$statePostUserName = $thistimeline["user"]["screen_name"];
	$statePostUserUid = $thistimeline["user"]["id"];
	$statePostUserName = $statePostUserName?$statePostUserName:$statePostUserUid;
	$statePostId = $thistimeline["id"];
	$statePostTime = $thistimeline["created_at"];
	$statePostSource = $thistimeline["source"];
	$statePostText = $thistimeline["text"];
	$statePostRetweet = $thistimeline["reply_comment"] ? $thistimeline["reply_comment"] : $thistimeline["status"];
	$statePostRetweet["id"] = $thistimeline["status"]["id"];
	if($i==0 && !$_GET["request"] && $_GET['type'] != "favorites"){
?>
<script type="text/javascript">
var max_id = "<?php echo $statePostId; ?>";
</script>
<?php
	}
	if(!$statePostUserHead){
		continue;
	}
?>
<div class="statePost" id="comment_<?php echo $statePostId; ?>">
<div class="stateUserHead" style="background: url(<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($statePostUserHead):$statePostUserHead; ?>)">
</div>
<div class="statePostContent">
<div class="statePostTrig"></div>
<div class="statePostInfo"><span class="statePostUserName"><a href="/user/<?php echo $statePostUserName; ?>"><?php echo $statePostUserName; ?></a></span> - <?php echo formatTime($statePostTime); ?> - 来自<?php echo $statePostSource; ?> - <span class="commentsReplayAction"><a href="##" onclick="document.getElementById('commentBoxDiv-<?php echo $statePostId; ?>').style.display='block';replayComment('replaybox-<?php echo $statePostId; ?>','<?php echo $statePostUserName; ?>','commentid-<?php echo $statePostId; ?>','<?php echo $statePostId; ?>');document.getElementById('commentbox-<?php echo $statePostId; ?>').focus();return false;">回复</a><?php if($statePostRetweet["user"]["id"] == $uid){ ?> - <a href="##" onclick="delComment(<?php echo $statePostId; ?>);return false;">删除</a><?php } ?></span></div><div style="clear: both"></div>
<div class="statePostWords">
<div>
<?php
echo format($statePostText);
?>
<div class="stateRepost">
<div class="statePostInfo"><span class="statePostUserName"><a href="/user/<?php echo $statePostRetweet["user"]["screen_name"]; ?>"><?php echo $statePostRetweet["user"]["screen_name"]; ?></a></span> - <a href="/post/<?php echo $statePostRetweet["id"]; ?>"><?php echo formatTime($statePostRetweet["created_at"]); ?></a> - 来自<?php echo $statePostRetweet["source"]; ?></div><?php if($statePostRetweet["reposts_count"]){?><div class="repostCount"> - <?php echo $statePostRetweet["reposts_count"]; ?></div><?php } ?><div style="clear: both"></div>
<?php
$statePostText = $statePostRetweet["text"];
echo format($statePostText);
?>
<?php if($statePostRetweet["bmiddle_pic"]){ ?>
<div class="statePostImageOuter"><img onclick="showImage('<?php echo $statePostRetweet["original_pic"]; ?>');" class="statePostImage" src="<?php echo $_SERVER['HTTPS']?"/qsimg/".base64_encode($statePostRetweet["bmiddle_pic"]):$statePostRetweet["bmiddle_pic"]; ?>"></div>
<?php } ?>
</div>
</div>

</div>

<div id="commentBoxDiv-<?php echo $statePostId; ?>" style="display: none; margin-top: 10px;" class="statePostCommentBoxDiv">
<div class="statePostCommentBox">
<div id="commentid-<?php echo $statePostId; ?>" style="visibility: hidden; height: 0;"></div>
<table>
<tr>
<td class="statePostCommentBoxReplay" id="replaybox-<?php echo $statePostId; ?>"></td>
<td class="statePostCommentInnerBox"><input type="text" id="commentbox-<?php echo $statePostId; ?>" onfocus="if(this.value == '添加评论'){this.value='';this.style.color='#000000';}" onblur="if(this.value==''){this.style.color='#888888';this.value='添加评论'};" onkeydown="if(event.keyCode==13){return false;}" class="statePostCommentInnerInput" value="添加评论" /></td>
</tr>
</table>
</div>
<div class="statePostCommentButton" onclick="replaynew('<?php echo $statePostRetweet["id"]; ?>', document.getElementById('commentbox-<?php echo $statePostId; ?>').value, document.getElementById('commentid-<?php echo $statePostId; ?>').innerHTML, 0, 'comment-<?php echo $statePostId; ?>', 1);document.getElementById('commentbox-<?php echo $statePostId; ?>').style.color='#888888';document.getElementById('commentbox-<?php echo $statePostId; ?>').value='添加评论';document.getElementById('commentid-<?php echo $statePostId; ?>').innerHTML='';document.getElementById('replaybox-<?php echo $statePostId; ?>').style.display='none';document.getElementById('replaybox-<?php echo $statePostId; ?>').innerHTML='';">评　论</div>
<div class="floatClear"></div>
</div>

</div>
<div class="floatClear"></div>
</div>
<?php
}
?>